﻿<UserControl x:Class="Gat.Controls.OpenDialogView35"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
			 xmlns:local="clr-namespace:Gat.Controls"
			 xmlns:models="clr-namespace:Gat.Controls.Model"
			 xmlns:frmwrk="clr-namespace:Gat.Controls.Framework"
			 xmlns:wtk="http://schemas.microsoft.com/wpf/2008/toolkit"
			 mc:Ignorable="d"
			 d:DesignHeight="300"
			 d:DesignWidth="300">

	<UserControl.Resources>
		<frmwrk:VisibilityConverter x:Key="VisibilityConverter" />
	</UserControl.Resources>
	<UserControl.DataContext>
		<local:OpenDialogViewModel35 x:Name="ViewModel"
									 ShowOpenDialogEventHandler="OnShow"
									 CloseOpenDialogEventHandler="OnClose" />
	</UserControl.DataContext>

	<Grid>

		<Grid.RowDefinitions>
			<RowDefinition Height="*" />
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
		</Grid.RowDefinitions>

		<Grid Grid.Row="0">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="*" />
				<ColumnDefinition Width="Auto" />
				<ColumnDefinition Width="2*" />
			</Grid.ColumnDefinitions>

			<TreeView x:Name="Folders"
					  Grid.Column="0"
					  SelectedItemChanged="Folders_SelectedItemChanged"
					  ItemsSource="{Binding Items}">
				<TreeView.Resources>
					<HierarchicalDataTemplate DataType="{x:Type models:OpenFolderRoot}"
											  ItemsSource="{Binding Children}">
						<StackPanel Orientation="Horizontal"
									VerticalAlignment="Stretch"
									Margin="0,5,0,5">
							<Image Source="{Binding Path=Image, Mode=OneTime}"
								   Stretch="Fill" />
							<TextBlock Text="{Binding Name}"
									   Margin="5,0" />
						</StackPanel>
					</HierarchicalDataTemplate>
					<HierarchicalDataTemplate DataType="{x:Type models:OpenFolderItem}"
											  ItemsSource="{Binding Children}">
						<StackPanel Orientation="Horizontal"
									VerticalAlignment="Stretch"
									Margin="0,2,0,2">
							<Image Source="{Binding Path=Image, Mode=OneTime}"
								   Stretch="Fill" />
							<TextBlock Text="{Binding Name}"
									   Margin="5,0" />
						</StackPanel>
					</HierarchicalDataTemplate>
				</TreeView.Resources>
			</TreeView>

			<GridSplitter Grid.Column="1"
						  Width="5"
						  ResizeBehavior="PreviousAndNext" />

			<wtk:DataGrid x:Name="Folder"
						  Grid.Column="2"
						  ItemsSource="{Binding Folder}"
						  SelectedItem="{Binding SelectedFile}"
						  AutoGenerateColumns="False"
						  CanUserAddRows="False"
						  CanUserDeleteRows="False"
						  CanUserResizeRows="False"
						  IsReadOnly="True"
						  SelectionUnit="FullRow"
						  ColumnWidth="Auto"
						  Background="Transparent"
						  GridLinesVisibility="None"
						  SelectionMode="Single">
				<wtk:DataGrid.CellStyle>
					<Style TargetType="wtk:DataGridCell">
						<Style.Triggers>
							<Trigger Property="IsSelected"
									 Value="True">
								<Setter Property="BorderThickness"
										Value="0" />
							</Trigger>
						</Style.Triggers>
					</Style>
				</wtk:DataGrid.CellStyle>
				<wtk:DataGrid.Columns>
					<wtk:DataGridTemplateColumn IsReadOnly="True">
						<wtk:DataGridTemplateColumn.Header>
							<TextBlock Text="{Binding DataContext.NameText, RelativeSource={RelativeSource AncestorType={x:Type wtk:DataGrid}}}" />
						</wtk:DataGridTemplateColumn.Header>
						<wtk:DataGridTemplateColumn.CellTemplate>
							<DataTemplate>
								<StackPanel Orientation="Horizontal"
											VerticalAlignment="Stretch"
											Height="Auto"
											Margin="5,2">
									<Image Source="{Binding Path=Image, Mode=OneTime}"
										   Stretch="None" />
									<TextBlock Text="{Binding Name}"
											   VerticalAlignment="Center"
											   Margin="3,0,0,0" />
								</StackPanel>
							</DataTemplate>
						</wtk:DataGridTemplateColumn.CellTemplate>
					</wtk:DataGridTemplateColumn>
					<wtk:DataGridTemplateColumn IsReadOnly="True">
						<wtk:DataGridTemplateColumn.Header>
							<TextBlock Text="{Binding DataContext.DateText, RelativeSource={RelativeSource AncestorType={x:Type wtk:DataGrid}}}" />
						</wtk:DataGridTemplateColumn.Header>
						<wtk:DataGridTemplateColumn.CellTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding Date}"
										   Margin="5,5,5,0" />
							</DataTemplate>
						</wtk:DataGridTemplateColumn.CellTemplate>
					</wtk:DataGridTemplateColumn>
					<wtk:DataGridTemplateColumn IsReadOnly="True">
						<wtk:DataGridTemplateColumn.Header>
							<TextBlock Text="{Binding DataContext.TypeText, RelativeSource={RelativeSource AncestorType={x:Type wtk:DataGrid}}}" />
						</wtk:DataGridTemplateColumn.Header>
						<wtk:DataGridTemplateColumn.CellTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding Type}"
										   Margin="5,5,5,0" />
							</DataTemplate>
						</wtk:DataGridTemplateColumn.CellTemplate>
					</wtk:DataGridTemplateColumn>
					<wtk:DataGridTemplateColumn IsReadOnly="True">
						<wtk:DataGridTemplateColumn.Header>
							<TextBlock Text="{Binding DataContext.SizeText, RelativeSource={RelativeSource AncestorType={x:Type wtk:DataGrid}}}" />
						</wtk:DataGridTemplateColumn.Header>
						<wtk:DataGridTemplateColumn.CellTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding Size}"
										   HorizontalAlignment="Right"
										   Margin="5,5,5,0" />
							</DataTemplate>
						</wtk:DataGridTemplateColumn.CellTemplate>
					</wtk:DataGridTemplateColumn>
				</wtk:DataGrid.Columns>
			</wtk:DataGrid>

		</Grid>

		<Grid Grid.Row="1"
			  Margin="10,10,10,0">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto" />
				<ColumnDefinition Width="*" />
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition />
				<RowDefinition />
			</Grid.RowDefinitions>
			<Label x:Name="FileNameLabel"
				   Grid.Column="0"
				   Grid.Row="0"
				   Margin="0,5"
				   Content="{Binding FileNameText}" />
			<TextBox x:Name="FileName"
					 Text="{Binding SelectedFilePath}"
					 Grid.Column="1"
					 Grid.Row="0"
					 Margin="0,5" />

			<Label x:Name="FileFilterLabel"
				   Grid.Column="0"
				   Grid.Row="1"
				   Margin="0,5"
				   Content="{Binding FileFilterText}" />
			<ComboBox x:Name="FileFilter"
					  ItemsSource="{Binding FileFilterExtensions}"
					  SelectedItem="{Binding SelectedFileFilterExtension}"
					  Grid.Column="1"
					  Grid.Row="1"
					  Margin="0,5" />
		</Grid>

		<Grid Grid.Row="2">
			<UniformGrid Rows="1"
						 HorizontalAlignment="Right"
						 MinHeight="45">
				<Button x:Name="Save"
						Margin="10"
						MinWidth="100"
						Visibility="{Binding SaveVisibility, Converter={StaticResource VisibilityConverter}}"
						Command="{Binding OpenCommand}"
						Content="{Binding SaveText}" />
				<Button x:Name="Open"
						Margin="10"
						MinWidth="100"
						Visibility="{Binding OpenVisibility, Converter={StaticResource VisibilityConverter}}"
						Command="{Binding OpenCommand}"
						Content="{Binding OpenText}" />
				<Button x:Name="Cancel"
						Margin="10"
						MinWidth="100"
						Command="{Binding CancelCommand}"
						Content="{Binding CancelText}" />
			</UniformGrid>
		</Grid>
	</Grid>
</UserControl>
